import random
from concurrent.futures import ThreadPoolExecutor
colors = ['红', '黄', '蓝', '绿', '紫']
colors3 = ['红', '黄', '蓝']
colors4 = ['红', '黄', '蓝', '绿']

def draw_beads():
    all_beads = [color for color in colors for _ in range(4)]
    drawn_beads = random.sample(all_beads, 10)
    result = {}
    for color in colors:
        result[color] = drawn_beads.count(color)
    sorted_result = sorted(result.values(), reverse=True)
    return "".join(str(count) for count in sorted_result)


def run_simulations(n):
    results = {}
    for _ in range(n):
        draw_result = draw_beads()
        if draw_result in results:
            results[draw_result] += 1
        else:
            results[draw_result] = 1
    total = sum(results.values())
    for result, count in results.items():
        results[result] = count / total
    return results

# 运行模拟1000000次
# print(run_simulations(1000000))


def draw_three_beads():
    all_beads = [color for color in colors3 for _ in range(8)]
    drawn_beads = random.sample(all_beads, 12)
    result = {}
    for color in colors3:
        result[color] = drawn_beads.count(color)
    sorted_result = sorted(result.values(), reverse=True)
    return "".join(str(count) for count in sorted_result)

def run_three_simulations(n):
    results = {}
    for _ in range(n):
        draw_result = draw_three_beads()
        if draw_result in results:
            results[draw_result] += 1
        else:
            results[draw_result] = 1
    total = sum(results.values())
    for result, count in results.items():
        results[result] = count / total
    return results

def draw_four_beads():
    all_beads = [color for color in colors4 for _ in range(5)]
    drawn_beads = random.sample(all_beads, 10)
    result = {}
    for color in colors4:
        result[color] = drawn_beads.count(color)
    sorted_result = sorted(result.values(), reverse=True)
    return "".join(str(count) for count in sorted_result)

def run_four_simulations(n):
    results = {}
    for _ in range(n):
        draw_result = draw_four_beads()
        if draw_result in results:
            results[draw_result] += 1
        else:
            results[draw_result] = 1
    total = sum(results.values())
    for result, count in results.items():
        results[result] = count / total
    return results

# result1 = draw_three_beads()
# print(result1)
# data = run_four_simulations(1000000)

def run_simulations_with_threads(func, n, num_threads):
    with ThreadPoolExecutor(max_workers=num_threads) as executor:
        results = list(executor.map(func, [n // num_threads] * num_threads))
    combined_results = {}
    for result in results:
        for k, v in result.items():
            combined_results[k] = combined_results.get(k, 0) + v
    total = sum(combined_results.values())
    for k, v in combined_results.items():
        combined_results[k] = v / total
    return combined_results

data = run_simulations_with_threads(run_four_simulations, 1000000, 4)
for k, v in data.items():
    print(k, v)
